package com.midian.service.activity.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.midian.common.dao.BaseDaoTemplet;
import com.midian.common.dao.OrderHelper;
import com.midian.common.dao.SearchHelper;
import com.midian.common.dao.SearchHelper.Type;
import com.midian.common.exception.BizException;
import com.midian.common.pager.Pager;
import com.midian.model.activity.ActivityComment;
import com.midian.service.common.BaseService;
import com.midian.service.activity.IActivityCommentService;

/**
 * 图书评论业务实现类
 * @author Mengfh
 *
 */
@Service("activityCommentService")
public class ActivityCommentServiceImpl extends BaseService implements IActivityCommentService {
	/**图书评论DAO*/
	private BaseDaoTemplet<ActivityComment> activityCommentDAO;
	
	@Resource(name = "activityCommentDAO")
	public void setActivityCommentDAO(BaseDaoTemplet<ActivityComment> activityCommentDAO) {
		this.activityCommentDAO = activityCommentDAO;
	}

	@Override
	public ActivityComment add(ActivityComment target) throws BizException {
		this.activityCommentDAO.add(target);
		return target;
	}

	@Override
	public void update(ActivityComment target) throws BizException {
		this.activityCommentDAO.updateByConvertHql(target);
	}

	@Override
	public void delete(Serializable id) throws BizException {
		this.activityCommentDAO.delete(id);
	}

	@Override
	public void delete(Serializable[] ids) throws BizException {
		this.activityCommentDAO.delete(ids);
	}

	@Override
	public ActivityComment get(Serializable id) throws BizException {
		return this.activityCommentDAO.get(id);
	}

	@Override
	public List<ActivityComment> showList(ActivityComment target, Pager pager, List<OrderHelper> helper) throws BizException {
		return this.activityCommentDAO.find(target, getSearchHelper(), helper, pager);
	}

	@Override
	public void opDelFlag(Serializable[] ids, Integer status) throws BizException {
		this.activityCommentDAO.opDelFlag(ids, status);
	}

	@Override
	protected List<SearchHelper> getSearchHelper() {
		String[] attrs = {"user","activity","user.account","content","delFlag"};
		Type[] types =  {Type.LEFTFETCH,Type.LEFTFETCH,Type.LIKE,Type.LIKE,Type.EQ};
		return SearchHelper.getSearchList(attrs, types);
	}

	@Override
	public List getResultsBysql(String sql) throws BizException {
		return this.activityCommentDAO.executeQuerySql(sql);
	}

	@Override
	public List getResultsBysql(String sql, Object[] values,Class entityClass) throws BizException {
		return this.activityCommentDAO.executeQuerySql(sql, values, entityClass);
	}
	
//	@Override
//	public int deleteBySql(String sql, Object[] values) throws BizException {
//		return this.activityCommentDAO.deleteBySql(sql, values);
//	}
	
}
